package adv.i31.robot;

import java.io.IOException;


import java.net.InetSocketAddress;
import java.net.UnknownHostException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;


// HAAAALLLLOOOOO

public class Main {

	public static void main(String[] args) throws JAXBException, InterruptedException,
			UnknownHostException, IOException {

		Server s = null;

			s = new Server();
	
		
		new Thread(s).start();
		synchronized (s) {
			s.wait();
		}

		JAXBContext context = JAXBContext.newInstance(Command.class);
		//JAXBContext context = JAXBContext.newInstance( new Class[] {Command.class});
		Marshaller m = context.createMarshaller();

		// don't start the output with <?xml version="1.0" encoding="UTF-8"
		// standalone="yes"?>
		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

		Command c = new Command();
		c.name = "AFUOIEFAHO";

		m.marshal(c, System.out);
		m.marshal(c, System.out);

		try {
			RobotConnectionIp4 con = new RobotConnectionIp4();
			con.connect(new InetSocketAddress("localhost", 123));

			m.marshal(c, con.getOutputStream());
		//	m.marshal(c, con.getOutputStream());
			con.disconnect();	
		} catch (IOException e) {
			e.printStackTrace();
		}
		

		//RobotConnectionFile con2 = new RobotConnectionFile();
		//m.marshal(c, con2.getOutputStream());
		//m.marshal(c, con2.getOutputStream());
	}

}
